import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-08-16
 * Time: 0:24
 */
//https://leetcode.cn/problems/minimum-size-subarray-sum/submissions/653437089/
public class Test {
    public static int minSubArrayLen(int target, int[] arr) {
        int n=0;  int sum=0;
        int p2=0;  int p1=0;
        int min=arr.length+1;
        while(p1<arr.length){
            if(sum<target){
                sum+=arr[p1];
                n++;p1++;
            }
            else{
                min=Math.min(min,n);
                sum-=arr[p2];
                p2++;n--;
            }
        }
        while(sum>=target&&p2<arr.length){
            min=Math.min(min,n);
            sum-=arr[p2];
            p2++;n--;
        }
        if(p2==0){
            return 0;
        }
        return min;
    }
    public static void main(String[] args) {
        int[] arr={12,28,83,4,25,26,25,2,25,25,25,12};
        System.out.println(minSubArrayLen(213,arr));

    }
}
